﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Data.SqlClient;
using System.Data;
using System.Collections;

namespace WineDAL
{
   public  class WineIndentDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 显示订单商品信息
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public ArrayList IndentShow(int id)
        {
            SqlParameter par = new SqlParameter("@id", id);
            DataTable table = helper.ExecDataTable_Proc("Indent_Show", par);
            JavaScriptSerializer jss = new JavaScriptSerializer();
            System.Collections.ArrayList dic = new System.Collections.ArrayList();
            foreach (DataRow dr in table.Rows)
            {
                System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
                foreach (DataColumn dc in table.Columns)
                {
                    drow.Add(dc.ColumnName, dr[dc.ColumnName]);
                }
                dic.Add(drow);
            }
            return dic;           
        }
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int IndentsDelete(int id)
        {
            SqlParameter[] pare = new SqlParameter[]{
            new SqlParameter("@id",id)
           };
            return helper.ExecNonquery_Proc("Indents_Delete", pare);
        }
       /// <summary>
       /// 添加订单信息
       /// </summary>
       /// <param name="UsersID"></param>
       /// <param name="IndentNumber"></param>
       /// <param name="Payfreght"></param>
       /// <param name="PayDue"></param>
       /// <param name="PayMent"></param>
       /// <param name="LeaveWord"></param>
       /// <param name="Express"></param>
       /// <param name="InventoryID"></param>
       /// <param name="Total"></param>
       /// <param name="ConsigneeID"></param>
       /// <param name="xml"></param>
       /// <returns></returns>
        public int AddIndent(int UsersID, int IndentNumber, decimal Payfreght, decimal PayDue, int PayMent, string LeaveWord, string Express, string InventoryID, decimal Total, int ConsigneeID, ArrayList xml)
        {
            string str="";
            str += "<ss>";
            foreach(System.Collections.Generic.Dictionary<string, object> item in xml)
            {
               
                str += "<cc GoodsID='" + item["GoodsID"] + "' IndNum='" + item["GoodsNum"] + "' IndPrice='" + item["GoodsPrice"] + "'/>";
               
            }
            str += "</ss>";
            SqlParameter[] par ={
                                   new SqlParameter("@UsersID", UsersID),
                                   new SqlParameter("@IndentNumbers",IndentNumber),
                                   new SqlParameter("@Payfreight",Payfreght),
                                   new SqlParameter("@PayDue",PayDue),
                                   new SqlParameter("@Payment",PayMent),
                                   new SqlParameter("@LeaveWord",LeaveWord),
                                   new SqlParameter("@Express",Express),
                                   new SqlParameter("@InventoryID",InventoryID),
                                   new SqlParameter("@Total",Total),
                                   new SqlParameter("@xml",str),
                                   new SqlParameter("@ConsigneeID",ConsigneeID)
                               };
            
            return helper.ExecNonquery_Proc("Pay_Indent", par);
        }
    }
}
